package com.itheima.并发工具类.hashmap;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.concurrent.ConcurrentHashMap;


/**
 * @Author 王加鑫
 * @Date 2021/5/23 16:23
 * @Version 1.0
 */
public class Demo01 {
    public static void main(String[] args) {

        //HashMap<String,String> map = new HashMap<>();

        //Hashtable<String,String> map = new Hashtable<>();

        ConcurrentHashMap<String,String> map = new ConcurrentHashMap<>();


        new Thread(() -> {
            for (int i = 0; i < 25; i++) {
                map.put(i + "",i + "");
            }
        }).start();

        new Thread(() -> {
            for (int i = 25; i < 51; i++) {
                map.put(i + "",i + "");
            }
        }).start();

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        for (int i = 0; i < 51; i++) {
            System.out.println(map.get(i + ""));
        }
    }
}
